package P3排序算法;

import java.util.Random;


public class TestSort {
    public static int N = 20000;
    public static int[] arr = new int[N];
    public static Random random = new Random();

    public static void getData01() {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(N);
        }
    }

    public static void getData02() {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(10);
        }
    }

    public static void getData03() {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i * 10;
        }
    }

    public static void getData04() {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (arr.length - i) * 10;
        }
    }

    public static int[] copy() {
        int[] newArr = new int[N];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }

    /*
    在对数据进行排序时，所消耗的时间除了和排序算法本身的策略有关之外
    还和数据本身的分布情况有关
    (1)完全随机
    (2)大致相等
    (3)大致升序
    (4)大致降序
    */
    public static void main(String[] args) {
        getData01();
        int[] arr1 = copy();
        int[] arr2 = copy();
        int[] arr3 = copy();
        int[] arr4 = copy();
        int[] arr5 = copy();
        int[] arr6 = copy();
        int[] arr7 = copy();
        int[] arr8 = copy();
        int[] arr9 = copy();
        int[] arr10 = copy();
        int[] arr11 = copy();
        int[] arr12 = copy();
        testSelectionSort(arr1);
        testBubbleSort(arr2);
        testInsertionSort(arr3);
        testShellSort(arr4);
        testMergeSort(arr5);
        testQuickSort01(arr6);
        testQuickSort02(arr7);
        testQuickSort03(arr8);
        testCountingSort(arr9);
        testHeapSort(arr10);
        testRadixSort(arr11);
        testMonkeySort(arr12);
    }

    private static void testMonkeySort(int[] arr) {
        System.out.println("猴子排序:");
        long start = System.currentTimeMillis();
        MonkeySort.monkeySort(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testRadixSort(int[] arr) {
        System.out.println("基数排序:");
        long start = System.currentTimeMillis();
        RadixSort.radixSort(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testHeapSort(int[] arr) {
        System.out.println("堆排序:");
        long start = System.currentTimeMillis();
        HeapSort.heapSort(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testCountingSort(int[] arr) {
        System.out.println("计数排序:");
        long start = System.currentTimeMillis();
        CountingSort.countingSortUpper(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testQuickSort03(int[] arr) {
        System.out.println("三路快排:");
        long start = System.currentTimeMillis();
        QuickSort03.quickSort(arr, 0, arr.length - 1);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testQuickSort02(int[] arr) {
        System.out.println("双路快排:");
        long start = System.currentTimeMillis();
        QuickSort02.quickSort(arr, 0, arr.length - 1);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testQuickSort01(int[] arr) {
        System.out.println("单路快排:");
        long start = System.currentTimeMillis();
        QuickSort01.quickSort(arr, 0, arr.length - 1);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testMergeSort(int[] arr) {
        System.out.println("归并排序:");
        long start = System.currentTimeMillis();
        MergeSort.mergeSort(arr, 0, arr.length - 1);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testShellSort(int[] arr) {
        System.out.println("希尔排序:");
        long start = System.currentTimeMillis();
        ShellSort.shellSort(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testInsertionSort(int[] arr) {
        System.out.println("插入排序:");
        long start = System.currentTimeMillis();
        InsertionSort.insertionSort(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testBubbleSort(int[] arr) {
        System.out.println("冒泡排序:");
        long start = System.currentTimeMillis();
        BubbleSort.bubbleSort(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }

    private static void testSelectionSort(int[] arr) {
        System.out.println("选择排序:");
        long start = System.currentTimeMillis();
        SelectionSort.selectionSort(arr);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }
}